package com.admgt.profile.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.HibernateTemplate;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.admgt.profile.entity.Profile;

@Repository("ProfileDAO")
@Transactional
public class ProfileDAOImpl implements ProfileDAO {

	private HibernateTemplate hibernateTemplate;
	
	@Autowired
	public void setSessionFactoty(SessionFactory sessionFactory){
		hibernateTemplate = new HibernateTemplate(sessionFactory);
	}
	
	@Override
	@Transactional(readOnly = false)
	public void saveProfile(Profile profile) {
		hibernateTemplate.saveOrUpdate(profile);
	}
	@Override
	@Transactional(readOnly = false)
	public void deleteProfile(Profile profile) {
		hibernateTemplate.delete(profile);
	}
	@Override
	@SuppressWarnings("unchecked")
	public List<Profile> getAllProfiles(Profile profile) {
		return (List<Profile>) hibernateTemplate.find(
			"from "+ Profile.class.getName());
	}

	@Override
	public Profile getProfileById(String profileId) {
		return hibernateTemplate.get(Profile.class, profileId);
	}
	
	

	
}
